class Admin::SaleRecordsController < Admin::BaseController
  before_action :set_sale_record, only: [:show, :change_state]
  def index
    @sale_records = SaleRecord.paginate(page: params[:page] || 1, per_page: params[:per_page] || 15).order("id desc")
  end

  def show
  end

  def change_state
    @sale_record.update_attribute(:state, !@sale_record.state)
    if @sale_record.state
      flash[:notice] = "关闭成功"
    else
      flash[:notice] = "打开成功"
    end
    redirect_to admin_sale_records_path
  end

  private

  def set_sale_record
    @sale_record = SaleRecord.find(params[:id])
  end
end
